package com.siyuanren.gcocp.service.impl;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.io.FileUtil;
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
import com.github.binarywang.wxpay.bean.order.WxPayMpOrderResult;
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
import com.github.binarywang.wxpay.service.WxPayService;
import com.siyuanren.gcocp.common.config.PublicConfig;
import com.siyuanren.gcocp.common.exception.BaseException;
import com.siyuanren.gcocp.common.util.UUIDUitl;
import com.siyuanren.gcocp.consts.GcocpConsts;
import com.siyuanren.gcocp.dto.ActiveInviteDTO;
import com.siyuanren.gcocp.entity.*;
import com.siyuanren.gcocp.enumm.CourseTeachType;
import com.siyuanren.gcocp.enumm.StatisticTypeEnum;
import com.siyuanren.gcocp.exception.WxException;
import com.siyuanren.gcocp.factory.WxTemplateMsgFac;
import com.siyuanren.gcocp.mapper.MyWxActiveMapper;
import com.siyuanren.gcocp.mapper.MyWxCourseMapper;
import com.siyuanren.gcocp.mapper.MyWxUserMapper;
import com.siyuanren.gcocp.mapper.MyWxUserVoucherMapper;
import com.siyuanren.gcocp.mapper.base.*;
import com.siyuanren.gcocp.service.*;
import com.siyuanren.gcocp.util.ObjectUtil;
import com.siyuanren.gcocp.util.QrCodeCreateUtil;
import com.siyuanren.gcocp.vo.*;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.exception.WxErrorException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.UUID;

/**
 * Created by   anxing
 * Project_name gcocp-parent
 * Path         com.siyuanren.gcocp.service
 * Date         2018/6/8
 * Time         15:22
 * Description
 */
@Slf4j
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    WxUserOrderMapper orderMapper;
    @Autowired
    MyWxUserVoucherMapper userVoucherMapper;
    @Autowired
    private WxCourseStartService courseStartService;
    @Autowired
    private MsgService msgService;
    @Autowired
    private MyWxUserMapper userMapper;
    @Autowired
    private MyWxCourseMapper courseMapper;
    @Autowired
    private WxTeacherMapper teacherMapper;
    @Autowired
    private WxUserCourseMapper userCourseMapper;
    @Autowired
    private WxCourseStatisticsMapper courseStatisticsMapper;
    @Autowired
    private UserVoucherService userVoucherService;
    @Autowired
    private WxPayService payService;
    @Autowired
    private WxTemplateMsgMapper templateMsgMapper;
    @Autowired
    private WxUserTimerTaskMapper userTimerTaskMapper;
    @Autowired
    private CourseService courseService;
    @Autowired
    private MyWxActiveMapper activeMapper;
    @Autowired
    private ActiveService activeService;
    @Autowired
    CourseStatisticsService courseStatisticsService;
    @Autowired
    WxGroupQrcodeMapper groupQrcodeMapper;
    @Autowired
    private WxVoucherMapper voucherMapper;

    @Override
    public WxUserOrder getBuyedCourse(Integer userId, Integer courseId) {
        WxUserOrderExample example = new WxUserOrderExample();
        example.or().andUserCourseIdEqualTo(userId).andCourseIdEqualTo(courseId).andPayStateEqualTo(1)
                .andAvailableEqualTo(true);
        List<WxUserOrder> wxUserOrders = orderMapper.selectByExample(example);
        if (wxUserOrders.isEmpty()) {
            return null;
        } else {
            return wxUserOrders.get(0);
        }
    }

    @Override
    @Transactional
    public int insert(WxUserOrder order) {
        return orderMapper.insert(order);
    }

    @Override
    @Transactional
    public int update(Integer orderId, WxUserOrder order) {
        order.setId(orderId);
        return orderMapper.updateByPrimaryKeySelective(order);
    }

    /**
     * @param result
     * @throws Exception
     */
    @Override
    public void completeOrder(WxPayOrderNotifyResult result) throws Exception {
        // 结果正确
        try {
            completeOrderRaw(result);
        } catch (Exception e) {
            log.info("异步通知处理失败！{}", e.getMessage());
            // 保存异常信息,后续人工处理
            try {
                String outTradeNo = result.getOutTradeNo();
                WxUserOrder order = getWxUserOrder(outTradeNo);
                order.setNormal(false);
                order.setAbnormalActualFee(result.getTotalFee());
                orderMapper.updateByPrimaryKeySelective(order);
            } catch (Exception e1) {
                log.error("订单异常:" + result.toString());
            }
            e.printStackTrace();
            throw new BaseException(e.getMessage());
        }
    }

    @Transactional
    void completeOrderRaw(WxPayOrderNotifyResult result) throws Exception {
        String outTradeNo = result.getOutTradeNo();
        WxUserOrder order = getWxUserOrder(outTradeNo);
        WxCourse course = courseMapper.selectByPrimaryKey(order.getCourseId());
        WxCourseStart courseStart = courseStartService.getLatestStart(course.getId());
        WxTeacher teacher = teacherMapper.selectByPrimaryKey(course.getTeacherId());
        WxUser user = userMapper.selectByPrimaryKey(order.getUserId());
        checkOrderVaild(result, order);
        // 更新订单状态
        updateOrderStatus(order);

        // 推送报名成功通知
        if (course.getTeachType() == CourseTeachType.FreeTeach.ordinal()) {
            sendPaySuccessNotify(course, new Date(), user);
        } else if (courseStart != null){
            sendPaySuccessNotify(course, courseStart.getCheckInTime(), user);
            timerEnterGroupMsg(course, courseStart, teacher, user);
            // 毕业消息暂停通知
//                timerGradMsg(course, courseStart, teacher, user);
//                timerGradVourcherMsg(course, courseStart, teacher, user);
        }
    }

    @Override
    @Transactional
    public void freeCourseOrder(FreeCourseOrderVO vo) throws Exception {
        // 结果正确
        WxCourse course = courseMapper.selectByPrimaryKey(vo.getCourseId());
        WxCourseStart courseStart = courseStartService.getLatestStart(course.getId());
        WxTeacher teacher = teacherMapper.selectByPrimaryKey(course.getTeacherId());
        WxUser user = userMapper.selectByPrimaryKey(vo.getUserId());
        WxUserOrder order = new WxUserOrder();
        WxUserCourseExample ucExam = new WxUserCourseExample();
        ucExam.or().andUserIdEqualTo(vo.getUserId()).andCourseIdEqualTo(vo.getCourseId());
        List<WxUserCourse> userCourseList = userCourseMapper.selectByExample(ucExam);
        if (!userCourseList.isEmpty()) {
            throw new BaseException("此课程已经购买过,请勿重复购买");
        }

        // 计算课程是否为免费课程
        QueryVoucherVO queryVo = new QueryVoucherVO();// 查询可用的优惠券
        queryVo.setUserId(vo.getUserId());
        queryVo.setCourseId(vo.getCourseId());
        int totalFee = ObjectUtil.isEmpty(course.getFavourableFee()) ? course.getCourseFee() : course.getFavourableFee();
        List<WxUserVoucher> wxUserVouchers = userVoucherService.getVoucherForCourse(queryVo);
        if (!wxUserVouchers.isEmpty()) {
            totalFee = totalFee - wxUserVouchers.get(0).getVoucherFee();
            order.setVoucherFee(wxUserVouchers.get(0).getVoucherFee());
            order.setUserVoucherId(wxUserVouchers.get(0).getId());
        }
        if (totalFee > 0) {
            throw new BaseException("此课程价格有误,请联系客服购买");
        }

        try {
            // 更新订单状态
            order.setOutTradeNo(UUID.randomUUID().toString().substring(0,5) + "_free");
            order.setFinalFee(0);
            order.setPayState(1);
            order.setCourseFee(course.getCourseFee());
            order.setCourseId(course.getId());
            order.setUserId(vo.getUserId());
            order.setSpbillCreateIp("empty");
            orderMapper.insertSelective(order);
            updateOrderStatus(order);
            // 推送报名成功通知
            if (course.getTeachType() == CourseTeachType.FreeTeach.ordinal()) {
                sendPaySuccessNotify(course, new Date(), user);
            } else if (courseStart != null){
                sendPaySuccessNotify(course, courseStart.getCheckInTime(), user);
                timerEnterGroupMsg(course, courseStart, teacher, user);
                // 毕业消息暂停通知
//                timerGradMsg(course, courseStart, teacher, user);
//                timerGradVourcherMsg(course, courseStart, teacher, user);
            }
        } catch (Exception e) {
            log.info("异步通知处理失败！{}", e.getMessage());
            e.printStackTrace();
        }
    }

    @Override
    @Transactional
    public WxPayMpOrderResult createOrder(CreateOrderVO vo) {
        WxUserCourseExample ucExam = new WxUserCourseExample();
        ucExam.or().andUserIdEqualTo(vo.getUserId()).andCourseIdEqualTo(vo.getCourseId());
        List<WxUserCourse> userCourseList = userCourseMapper.selectByExample(ucExam);
        if (!userCourseList.isEmpty()) {
            throw new BaseException("此课程已经购买过,请勿重复购买");
        }

        WxCourse course = courseMapper.selectByPrimaryKey(vo.getCourseId());
        WxUserOrder order = new WxUserOrder();
        order.setUserId(vo.getUserId());
        order.setCourseId(vo.getCourseId());
        order.setSpbillCreateIp(vo.getClientIP());
        order.setOutTradeNo(UUIDUitl.getOutTradeNo(vo.getUserId()));

        // 计算课程最终价格
        QueryVoucherVO queryVo = new QueryVoucherVO();// 查询可用的优惠券
        queryVo.setUserId(vo.getUserId());
        queryVo.setCourseId(vo.getCourseId());
        order.setCourseFee(course.getCourseFee());
        int courseFee = ObjectUtil.isEmpty(course.getFavourableFee()) ? course.getCourseFee() : course.getFavourableFee();
        List<WxUserVoucher> wxUserVouchers = userVoucherService.getVoucherForCourse(queryVo);
        if (!wxUserVouchers.isEmpty()) {
            order.setFinalFee(courseFee - wxUserVouchers.get(0).getVoucherFee());
            order.setVoucherFee(wxUserVouchers.get(0).getVoucherFee());
            order.setUserVoucherId(wxUserVouchers.get(0).getId());
        } else {
            order.setFinalFee(courseFee);
        }
        if (order.getFinalFee() <= 0) {
            log.error("courseFee={},favFee={},voucherFee={},finalFee={},",
                    course.getCourseFee(), course.getFavourableFee(), order.getVoucherFee(), order.getFinalFee());
            throw new BaseException("支付金额不正确,请联系管理员");
        }
        try {
            WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
            orderRequest.setBody(course.getCourseName());
            orderRequest.setOutTradeNo(order.getOutTradeNo());
            orderRequest.setTotalFee(order.getFinalFee());
            orderRequest.setSpbillCreateIp(vo.getClientIP());
            orderRequest.setAttach(String.valueOf(order.getId()));
            orderRequest.setNotifyUrl(PublicConfig.TOMCAT_URL + PublicConfig.PUBLIC_WX_NOTIFY_URL);
            String jsapi = "JSAPI";
            orderRequest.setTradeType(jsapi);
            orderRequest.setOpenid(userMapper.selectByPrimaryKey(vo.getUserId()).getOpenid());
            WxPayMpOrderResult result = payService.createOrder(orderRequest);

            // 保存订单
            orderMapper.insertSelective(order);
            log.info("result = {}" + result);
            return result;
        } catch (Exception e) {
            log.error("微信回调结果异常,异常原因{}", e.getMessage());
            throw new BaseException("微信回调结果异常,支付失败");
        }
    }

    /**
     * 检查订单是否有效
     * @param result
     * @param order
     */
    private void checkOrderVaild(WxPayOrderNotifyResult result, WxUserOrder order) {
        Integer totalFee = result.getTotalFee();
        Integer localTotalFee = order.getFinalFee();
        log.info("totalFee_{}_localTotalFee_{}", totalFee, localTotalFee);
        // 订单金额是否一致
        if (!Objects.equals(totalFee, localTotalFee)) {
            log.error("totalFee!=localTotalFee1,订单金额有误");
            throw WxException.PAY_ERROR.print();
        }
        Integer coursePayState = order.getPayState();
        // 订单支付状态是否为未支付
        log.info("coursePayState_{}", coursePayState);
        if (!Objects.equals(GcocpConsts.ZERO, coursePayState)) {
            log.error("totalFee!=courseCost,订单支付状态有误");
            throw WxException.PAY_ERROR.print();
        }
        log.info("订单金额验证通过，就让异步通知成功！");
    }

    /**
     * 获取order 信息
     * @param outTradeNo
     * @return
     */
    private WxUserOrder getWxUserOrder(String outTradeNo) {
        WxUserOrderExample example =new WxUserOrderExample();
        example.or().andOutTradeNoEqualTo(outTradeNo)
                .andAvailableEqualTo(true);
        List<WxUserOrder> orders = orderMapper.selectByExample(example);
        if (orders.isEmpty()) {
            log.error("userCourse is null,订单没记录");
            throw WxException.PAY_ERROR.print();
        }
        return orders.get(0);
    }


    /**
     * 报名成功提醒
     */
    public void sendPaySuccessNotify(WxCourse course, Date checkInDate, WxUser user) throws Exception {
        // 发送支付成功消息
        WxTemplateMsg templateMsg = WxTemplateMsgFac.getPaySuccessMsg(course,
                DateUtil.formatDate(checkInDate));
        msgService.sendTemplateMessage(user.getOpenid(), templateMsg);


    }

    /**
     * 定时入群消息
     * @param course
     * @param courseStart
     * @param teacher
     * @param user
     */
    public void timerEnterGroupMsg(WxCourse course, WxCourseStart courseStart, WxTeacher teacher, WxUser user) {
        // 定时报到消息
        WxTemplateMsg msg = WxTemplateMsgFac.getEnterGroupMsg(course,teacher.getTeacherName());
        templateMsgMapper.insertSelective(msg);
        WxUserTimerTask task = new WxUserTimerTask();
        task.setTemplateMsgId(msg.getId());
        task.setStartDate(courseStart.getCheckInTime());
        task.setEndDate(courseStart.getCheckInTime());
        task.setSendTime(7);
        task.setUserOpenId(user.getOpenid());
        userTimerTaskMapper.insertSelective(task);
    }

    /**
     * 定时毕业消息
     * @param course
     * @param courseStart
     * @param teacher
     * @param user
     */
    public void timerGradMsg(WxCourse course, WxCourseStart courseStart, WxTeacher teacher, WxUser user) {
        // 定时报到消息
        WxTemplateMsg msg = WxTemplateMsgFac.getGradMsg(course,teacher.getTeacherName(), user.getUserName());
        templateMsgMapper.insertSelective(msg);
        WxUserTimerTask task = new WxUserTimerTask();
        task.setTemplateMsgId(msg.getId());
        task.setStartDate(com.siyuanren.gcocp.util.DateUtil.getDateAfter(courseStart.getStartTime(), course.getChapterCount()));
        task.setEndDate(com.siyuanren.gcocp.util.DateUtil.getDateAfter(courseStart.getStartTime(), course.getChapterCount()));
        task.setSendTime(7);
        task.setUserOpenId(user.getOpenid());
        userTimerTaskMapper.insertSelective(task);
    }
    /**
     * 定时领取毕业优惠券消息
     * @param course
     * @param courseStart
     * @param teacher
     * @param user
     */
    public void timerGradVourcherMsg(WxCourse course, WxCourseStart courseStart, WxTeacher teacher, WxUser user) {
        WxTemplateMsg msg = WxTemplateMsgFac.getGradVoucherMsg(user);
        templateMsgMapper.insertSelective(msg);
        WxUserTimerTask task = new WxUserTimerTask();
        task.setTemplateMsgId(msg.getId());
        task.setStartDate(com.siyuanren.gcocp.util.DateUtil.getDateAfter(courseStart.getStartTime(), course.getChapterCount()));
        task.setEndDate(com.siyuanren.gcocp.util.DateUtil.getDateAfter(courseStart.getStartTime(), course.getChapterCount()));
        task.setSendTime(7);
        task.setUserOpenId(user.getOpenid());
        userTimerTaskMapper.insertSelective(task);
    }

    /**
     * 处理优惠卷,将优惠卷设置为已使用,并给推荐人发送使用信息
     */
    @Transactional
    public void updateOrderStatus(WxUserOrder order) throws Exception {
        Integer voucherId = order.getUserVoucherId();
        WxCourse course = courseMapper.selectByPrimaryKey(order.getCourseId());

        // 更新优惠券状态
        if (voucherId != null && voucherId != 0) {
            WxUserVoucher voucher = userVoucherMapper.selectByPrimaryKey(voucherId);
            log.info("处理优惠卷_{},设置为已使用",voucherId);
            voucher.setVoucherState(GcocpConsts.TWO);
            userVoucherMapper.updateByPrimaryKeySelective(voucher);

            Integer sponsorUserId = voucher.getSponsorUserId();
            if (sponsorUserId != null && sponsorUserId != 0) {
                if (voucher.getActiveId() == null || voucher.getActiveId() == 0) {
                    // 没有参加活动
                    sendInviteSuccNotify(sponsorUserId, voucher.getUserId(), order);
                } else {
                    // 参加活动
                    QueryActiveVO vo = new QueryActiveVO();
                    vo.setActiveId(voucher.getActiveId());
                    vo.setUserId(voucher.getSponsorUserId());
                    ActiveInviteDTO activeDetail = activeService.getActiveDetail(vo);
                    if (activeDetail.isInProgress() && activeDetail.getPlayerList().size() == PublicConfig.PUBLIC_ACTIVE_SUCCESS_FRIEND_COURT) {
                        // 活动参加成功
                        activeComplete(voucher);
                        // 发放课程  插入课程学习记录
//                        WxCourse sponsorCourse = courseService.getSponsorCourseByActive(voucher.getActiveId());
//                        addCourseToUser(voucher.getSponsorUserId(), sponsorCourse);
                    } else {
                        sendActiveProgressMsg(voucher, activeDetail);
                    }
                }
            }
        }

        // 插入课程学习记录
        int ucId = addCourseToUser(order.getUserId(), course);
        // 更新订单状态
        order.setPayState(1);
        order.setUserCourseId(ucId);
        orderMapper.updateByPrimaryKeySelective(order);
    }

    @Transactional
    int addCourseToUser(Integer userId, WxCourse course) throws Exception {
        String qrcodeUrl = null;
        WxVoucher voucher = voucherMapper.selectByPrimaryKey(course.getInviteVoucherId());
        if (voucher != null) {
            qrcodeUrl = QrCodeCreateUtil.genVoucherQRcode(userId, voucher.getCourseId(), voucher.getId());
        }
        WxCourseStart start = courseStartService.getLatestStart(course.getId());
        WxUserCourse userCourse = new WxUserCourse();
        userCourse.setUserId(userId);
        userCourse.setCourseId(course.getId());
        userCourse.setInviteFriendQrcodeUrl(qrcodeUrl);
        if (start != null) {
            setGroupQrcode(start, userCourse);
            userCourse.setCourseStartId(start.getId());
        }
        userCourseMapper.insertSelective(userCourse);

        // 更新课程订购数量
        WxCourseStatistics sta = courseStatisticsService.getCourseOrderCount(course.getId());
        if (sta == null) {
            sta = new WxCourseStatistics();
            sta.setCount(1);
            sta.setType(StatisticTypeEnum.CourseStati.ordinal());
            sta.setGoalId(course.getId());

            courseStatisticsMapper.insertSelective(sta);
        } else {
            sta.setCount(sta.getCount() + 1);
            courseStatisticsMapper.updateByPrimaryKeySelective(sta);
        }

        return userCourse.getId();
    }

    /**
     * 设置入群的二维码
     * @param start
     * @param userCourse
     */
    @Transactional
    void setGroupQrcode(WxCourseStart start, WxUserCourse userCourse) {
        if (start == null || userCourse == null) {
            return;
        }
        WxGroupQrcodeExample gqExample = new WxGroupQrcodeExample();
        gqExample.or().andAvailableEqualTo(true).andIsFullEqualTo(false).andCourseStartIdEqualTo(start.getId());
        List<WxGroupQrcode> groupQrcodeList = groupQrcodeMapper.selectByExample(gqExample);
        if (groupQrcodeList.size() > 0) {
            WxGroupQrcode groupQrcode = groupQrcodeList.get(0);
            userCourse.setGroupQrcodeId(groupQrcode.getId());

            // 判断当前群人数是否满了
            WxUserCourseExample ucExample = new WxUserCourseExample();
            ucExample.or().andCourseStartIdEqualTo(start.getId()).andGroupQrcodeIdEqualTo(groupQrcode.getId());
            long count = userCourseMapper.countByExample(ucExample);
            if (count > PublicConfig.PUBLIC_QRCODE_GROUP_MAX_COUNT) {
                groupQrcode.setIsFull(true);
                groupQrcodeMapper.updateByPrimaryKeySelective(groupQrcode);
            }
        }

    }

    private void sendInviteSuccNotify(int sponsorUserId, int playUserId, WxUserOrder order) {
        if (sponsorUserId == playUserId) {
            log.debug("邀请者和接受者同一个人,不发送通知. 一般出现于完成活动时的优惠券");
            return;
        }
        WxCourse course = courseMapper.selectByPrimaryKey(order.getCourseId());
        // 推荐人信息
        WxUser refereeUser = userMapper.selectByPrimaryKey(sponsorUserId);
        WxUser playerUser = userMapper.selectByPrimaryKey(playUserId);
        // 好友优惠券使用通知
        String userName = playerUser.getUserName();
        WxTemplateMsg msg = WxTemplateMsgFac.getFriendUseVoucherMsg(refereeUser,course, userName);
        msgService.sendTemplateMessage(refereeUser.getOpenid(), msg);
    }

    /**
     * 发送活动进度通知
     * @param userVoucher
     */
    private void sendActiveProgressMsg(WxUserVoucher userVoucher, ActiveInviteDTO activeDetail) {
        WxUser sponsorUser = userMapper.selectByPrimaryKey(userVoucher.getSponsorUserId());
        WxUser friendUser = userMapper.selectByPrimaryKey(userVoucher.getUserId());
        WxCourse course = courseService.getByActive(userVoucher.getActiveId());
        WxActive active = activeMapper.selectByPrimaryKey(userVoucher.getActiveId());
        int needFriendCount = PublicConfig.PUBLIC_ACTIVE_SUCCESS_FRIEND_COURT
                - (activeDetail.getPlayerList() == null ? 0:activeDetail.getPlayerList().size());
        WxTemplateMsg msg = WxTemplateMsgFac.getActiveProgressMsg(active,friendUser.getNickname(), needFriendCount, course.getCourseName());
        msgService.sendTemplateMessage(sponsorUser.getOpenid(), msg);
    }

    /**
     * 活动完成处理
     * 发送活动进度通知
     * @param userVoucher
     */
    @Transactional
    public void activeComplete(WxUserVoucher userVoucher) throws WxErrorException, IOException {
        WxUser sponsorUser = userMapper.selectByPrimaryKey(userVoucher.getSponsorUserId());
        WxUser friendUser = userMapper.selectByPrimaryKey(userVoucher.getUserId());
        WxCourse sponsorCourse = courseService.getSponsorCourseByActive(userVoucher.getActiveId());
        WxCourse friendCourse = courseService.getByActive(userVoucher.getActiveId());
        WxActive active = activeMapper.selectByPrimaryKey(userVoucher.getActiveId());
        WxTemplateMsg msg = WxTemplateMsgFac.getActiveCompleteMsg(active, friendUser.getNickname(), friendCourse.getCourseName());
        msgService.sendTemplateMessage(sponsorUser.getOpenid(), msg);

        // 发送课程优惠券
        SendVoucherVO vo = new SendVoucherVO();
        vo.setUserId(sponsorUser.getId());
        vo.setActiveId(active.getId());
        vo.setCourseId(sponsorCourse.getId());
        vo.setVoucherId(active.getSponsorVoucherId());
        activeService.sendVoucher(vo);
        // 发送课程购买图片消息
        String activeQrcodePath = QrCodeCreateUtil.genActiveSponsorCourse(sponsorUser.getId(), sponsorCourse.getId(), active);
        File file = FileUtil.file(PublicConfig.USER_DATA_PATH + activeQrcodePath);
        msgService.sendFileToUser(sponsorUser.getOpenid(), file);
    }

}
